<?php

namespace App\Admin\Controllers;

use App\Models\DrinkCategory;
use App\Models\DrinkAttr;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Controllers\AdminController;

class DrinkAttrsController extends AdminController
{
    protected $title = '畅饮属性值';
    
    protected function grid()
    {
        $grid = new Grid(new DrinkAttr());
	
	    $grid->disableExport();
	    $grid->column('drink_category_id', '属性分类')->display(function () {
            return isset($this->drinkCategory) ? "{$this->drinkCategory->id}: {$this->drinkCategory->name}" : '';
        });
	    $grid->column('name', '畅饮属性值名称');
        $grid->column('price', '价格');

	    $grid->column('created_at', '创建时间')->display(function () {
	    	return $this->created_at->toDatetimeString();
	    });
	    
        return $grid;
    }
    
    protected function detail($id)
    {
        $show = new Show(DrinkAttr::findOrFail($id));



        return $show;
    }
    
    protected function form()
    {
        $form = new Form(new DrinkAttr());
         $form->select('drink_category_id','畅饮属性分类')->options(DrinkCategory::all()->pluck('name', 'id'));
	    $form->text('name', '畅饮属性分类名称');
        $form->currency('price', '价格')->symbol('￥')->default(0);
	    

        return $form;
    }

   
   
}
